package com.ballmaze.controllers;

import com.ballmaze.conn.Result;
import com.ballmaze.maze.MazeAction;
import com.ballmaze.maze.MazeManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
public class MazeStatusController {

    @Autowired
    MazeManager mazeManager;

    /**
     * 启动MazeManager
     *
     * @param request HTTP请求
     * @return
     */
    @GetMapping("/activate")
    public Result activate(HttpServletRequest request) {
        mazeManager.getStatusController().activate();
        return Result.success("成功激活", null);
    }

    /**
     * 停止MazeManager
     *
     * @param request HTTP请求
     * @return
     */
    @GetMapping("/deactivate")
    public Result deactivate(HttpServletRequest request) {
        mazeManager.getStatusController().deactivate();
        return Result.success("成功停止", null);
    }

    /**
     * 重启MazeManager
     *
     * @param request HTTP请求
     * @return
     */
    @GetMapping("/restart")
    public Result restart(HttpServletRequest request) {
        mazeManager.getStatusController().restart();
        return Result.success("成功停止", null);
    }

    /**
     * 检查当前MazeManager的状态
     *
     * @param request
     * @return
     */
    @GetMapping("/alive")
    public Result status(HttpServletRequest request) {
        if (mazeManager.getStatusController().isAlive()) {
            return Result.success("运行中", true);
        } else {
            return Result.success("停止中", false);
        }
    }
}